{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "Secrets" %}{% endblock %}
{% block content %}
    {% include 'sidebar.html' %}
    <div class="main col-xs-12 col-sm-9">
        {% if errors %}
            {% for error in errors %}
                <div class="alert alert-danger">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    {{ error }}
                </div>
            {% endfor %}
        {% endif %}
        <div class="btn-group-sm">
            <a href="#AddSecret" class="btn btn-success" data-toggle="modal">{% trans "New Secret" %}</a>
        </div>
        {% if secrets_all %}
            <table class="table" role="main">
                <thead>
                <tr class="active">
                    <th>{% trans "UUID" %}</th>
                    <th>{% trans "Type" %}</th>
                    <th>{% trans "Usage" %}</th>
                    <th style="width:90px;">{% trans "Action" %}</th>
                </tr>
                </thead>
                <tbody>
                {% for secret in secrets_all %}
                    <tr>
                        <td>{{ secret.uuid }}</td>
                        <td>{% ifequal secret.usageType 0 %}
                            {% trans "volume" %}
                        {% endifequal %}
                            {% ifequal secret.usageType 1 %}
                                {% trans "iscsi" %}
                            {% endifequal %}
                            {% ifequal secret.usageType 2 %}
                                {% trans "ceph" %}
                            {% endifequal %}
                        </td>
                        <td>{{ secret.usage }}</td>
                        <td>
                            <form action="" method="post" role="form">{% csrf_token %}
                                <input type="hidden" name="uuid" value="{{ secret.uuid }}"/>
                                <a data-toggle="modal" href="#editSecret{{ secret.uuid }}"
                                   class="btn btn-sm btn-primary" title="{% trans "Edit" %}">
                                    <span class="glyphicon glyphicon-pencil"></span>
                                </a>
                                <button type="submit" class="btn btn-sm btn-danger" name="delete"
                                        title="{% trans "Delete" %}"
                                        onclick="return confirm('{% trans "Are you sure?" %}')">
                                    <span class="glyphicon glyphicon-trash"></span>
                                </button>
                            </form>
                            <!-- Modal -->
                            <div class="modal fade" id="editSecret{{ secret.uuid }}" tabindex="-1" role="dialog"
                                 aria-labelledby="editSecret" aria-hidden="true">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal"
                                                    aria-hidden="true">&times;</button>
                                            <h4 class="modal-title">{% trans "Set secret value" %}</h4>
                                        </div>
                                        <div class="tab-content">
                                            <form class="form-horizontal" method="post" role="form">{% csrf_token %}
                                                <div class="form-group">
                                                    <label class="col-sm-3 control-label">{% trans "Value" %}</label>

                                                    <div class="col-sm-6">
                                                        <input type="hidden" name="uuid" value="{{ secret.uuid }}">
                                                        <input type="text" name="value" class="form-control"
                                                               value="{{ secret.value }}" maxlength="45" required
                                                               pattern="[a-zA-Z0-9]$+">
                                                    </div>
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-default"
                                                            data-dismiss="modal">{% trans "Close" %}</button>
                                                    <button type="submit" class="btn btn-primary"
                                                            name="set_value">{% trans "Set" %}</button>
                                                </div>
                                            </form>
                                        </div>
                                        <!-- /.modal-content -->
                                    </div>
                                    <!-- /.modal-dialog -->
                                </div>
                                <!-- /.modal -->
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        {% else %}
            <div class="well" role="main">
                <h4>{% trans "You do not have any Secrets" %}</h4>
            </div>
        {% endif %}
    </div>

    <!-- Modal Secret -->
    <div class="modal fade" id="AddSecret" tabindex="-1" role="dialog" aria-labelledby="AddSecret" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">{% trans "Create New Secret" %}</h4>
                </div>
                <div class="tab-content">
                    <form class="form-horizontal" method="post" action="" role="form">{% csrf_token %}
                        <div class="form-group">
                            <label class="col-sm-3 control-label">{% trans "Ephemeral" %}</label>

                            <div class="col-sm-6">
                                <select name="ephemeral" class="form-control">
                                    <option value="no">{% trans "no" %}</option>
                                    <option value="yes">{% trans "yes" %}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">{% trans "Private" %}</label>

                            <div class="col-sm-6">
                                <select name="private" class="form-control">
                                    <option value="no">{% trans "no" %}</option>
                                    <option value="yes">{% trans "yes" %}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">{% trans "Usage" %}</label>

                            <div class="col-sm-6">
                                <select name="usage_type" class="form-control">
                                    <option value="ceph">{% trans "ceph" %}</option>
                                    <option value="volume">{% trans "volume" %}</option>
                                    <option value="iscsi">{% trans "iscsi" %}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">{% trans "Data" %}</label>

                            <div class="col-sm-6">
                                <input type="text" name="data" class="form-control" value="" required
                                       pattern="[a-z0-9\. ]+"/>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default"
                                    data-dismiss="modal">{% trans "Close" %}</button>
                            <button type="submit" class="btn btn-primary" name="create">{% trans "Create" %}</button>
                        </div>
                    </form>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div><!-- /.modal -->
{% endblock %}
